package com.example.hi;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.HashMap;

public class RateListActivity extends AppCompatActivity implements  AdapterView.OnItemClickListener{
    Handler handler;
    ListView listView;
    public static final String TAG="ssssssssssss";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rate_list);
        listView=findViewById(R.id.mylist1);

        String[] list_data={"one","two","three","four"};
        ListAdapter adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,list_data);

//        listView.setListAdapter(adapter);


        handler=new Handler(Looper.myLooper()){
            @Override
            public void handleMessage(@NonNull Message msg) {
                if(msg.what==7){
                    ArrayList<String> rlist=(ArrayList<String>)msg.obj;
                    //List<String> list2=(List<String>) msg.obj;
                    ListAdapter adapter=new ArrayAdapter<String>(RateListActivity.this, android.R.layout.simple_list_item_1,rlist);
                    listView.setAdapter(adapter);
                    listView.setOnItemClickListener(RateListActivity.this);
                }

                super.handleMessage(msg);
            }
        };
        //开启线程
//        MyThrea t=new MyThrea();
//        t.setHandler(handler);
//        Thread td=new Thread(t);
//        td.start();

        RateThread dt=new RateThread(handler);
        Thread t=new Thread(dt);
        t.start();
    }
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Object item= listView.getItemAtPosition(position);
        HashMap<String,String> hashMap= (HashMap<String, String>) item;
        String name=hashMap.get("name");
        String value=hashMap.get("value");
        Intent intent=new Intent(RateListActivity.this,Show2Activity.class);
        intent.putExtra("name",name);
        intent.putExtra("value",value);
        Log.d(TAG, "onItemClick: guyufytyftyy");
        startActivity(intent);
    }




}